package com.ruibang.glass.material.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.material.constant.MaterialWareHouseCode;
import com.ruibang.glass.material.entity.MaterialInventoryItem;
import com.ruibang.glass.material.service.MaterialInventoryItemService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 采购入库物品信息
 * </p>
 *
 * @author wujie
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/api/material/inventory/item")
@Api(value = "采购入库物品信息", tags = {"采购入库物品信息"})
public class MaterialInventoryItemController {
    @Autowired
    private MaterialInventoryItemService inventoryItemService;


    @PostMapping("/batchAdd")
    @ApiOperation(value = "批量新增采购入库物品信息", response = ResultBody.class)
    public ResultBody batchAdd(@RequestBody List<MaterialInventoryItem> inventoryItems) {
        inventoryItemService.saveBatch(inventoryItems);
        return ResultBody.success();
    }

    @PostMapping("/updateQualityByNumber")
    @ApiOperation(value = "根据Id更新物品数据", response = ResultBody.class)
    public ResultBody updateQualityByNumber(@RequestBody List<MaterialInventoryItem> inventoryItems) {
        inventoryItemService.updateQualityByNumber(inventoryItems);
        return ResultBody.success();
    }


    @GetMapping("/getYCLIdList")
    @ApiOperation(value = "查询所有原材料Id", response = ResultBody.class)
    public ResultBody getYCLIdList() {
        List<MaterialInventoryItem> list = inventoryItemService.list(Wrappers.
                <MaterialInventoryItem>lambdaQuery().select(MaterialInventoryItem::getItemId)
                .eq(MaterialInventoryItem::getWarehouseCode, MaterialWareHouseCode.YCLK_CK.getMsg())
        );
        List<String> collect = list.stream().map(MaterialInventoryItem::getItemId).distinct().collect(Collectors.toList());
        return ResultBody.success(collect);
    }



}
